<template lang="html">
  <el-form
    ref="form"
    label-width="auto"
    class="page-header"
    :inline="true"
    :model="form"
    label-suffix=":"
  >
    <el-row :gutter="10">
      <el-col :xs="8" :sm="6" :md="5">
        <el-form-item label="菜单名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入" @keyup.enter.native="doSearch" />
        </el-form-item>
      </el-col>
      <el-col :xs="8" :sm="6" :md="5">
        <el-form-item label="菜单状态" prop="state">
          <el-select v-model="form.state" placeholder="请选择" clearable @change="doSearch">
            <el-option
              v-for="item in [
                { name: '显示', value: '1' },
                { name: '隐藏', value: '0' },
              ]"
              :key="item.value"
              :label="item.name"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
      </el-col>

      <el-col :xs="8" :sm="6" :md="4">
        <div style="width: 300px">
          <el-button icon="el-icon-search" @click="doSearch">搜索</el-button>
          <el-button icon="el-icon-refresh" @click="doReset">重置</el-button>
        </div>
      </el-col>
    </el-row>
  </el-form>
</template>

<script>
import pageHeaderMixin from "mixins/pageHeaderMixin";

export default {
  mixins: [pageHeaderMixin],
  data() {
    return {
      form: {
        // 状态
        state: "",
        // 菜单名称
        name: "",
      },
    };
  },

  watch: {
    // affiliationApp(newVal) {
    //   if (newVal) {
    //     Object.assign(this.form, { affiliationApp: newVal });
    //   }
    // },
  },
  created() {
    // this._DictKeys();
    this.selectChange({ type: 0 });
  },
  methods: {
    /**
     * 新增
     */
    doAdd() {
      this.$emit("doAdd", this.form);
    },
    /**
     * select切换
     */
    selectChange() {
      this.$emit("success", {
        searchObj: this.form,
        // ...(type !== 1 && {
        //   affiliationAppOptions: this.affiliationAppOptions,
        //   affiliationAppTypeOptions: this.affiliationAppTypeOptions,
        // }),
      });
    },
    /**
     * 获取数据字典
     */
    // async _DictKeys() {
    //   try {
    //     this.$emit("startLoading");
    //     const data = await DictKeys("affiliation_app_type,affiliation_app");
    //     if (!data) return false;
    //     const { affiliation_app: affiliationApp, affiliation_app_type: affiliationAppType } = data;
    //     this.affiliationAppOptions = affiliationApp;
    //     this.affiliationAppTypeOptions = affiliationAppType;
    //     this.setDefaultVal();
    //     this.selectChange({ type: 0 });
    //   } catch (e) {
    //     console.log(e);
    //     this.$emit("closeLoading");
    //   }
    // },
    /**
     * 设置默认值
     */
    // setDefaultVal() {
    //   this.form.affiliationApp = getPublicConfig({ key: "affiliationApp" });
    //   this.form.affiliationAppType = getPublicConfig({
    //     key: "affiliationAppType",
    //   });
    // },
    /**
     * 重置
     */
    doReset() {
      this.$refs.form.resetFields();
      this.setDefaultVal();
      this.$emit("doSearch");
    },
  },
};
</script>
